using Microsoft.AspNetCore.Mvc;
using ConsoleApi.Models;
using ConsoleApi.Services.Console;
using MESData.ErrorCode;

namespace ConsoleApi.Controllers
{
    /// <summary>
    /// 通知公告控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class AnnouncementController : ControllerBase
    {
        private readonly IConsoleService _consoleService;

        public AnnouncementController(IConsoleService consoleService)
        {
            _consoleService = consoleService;
        }

        /// <summary>
        /// 获取通知公告列表
        /// </summary>
        [HttpGet]
        public async Task<ApiResult<PagedResultDto<AnnouncementDto>>> GetAnnouncements([FromQuery] AnnouncementQueryDto query)
        {
            return await _consoleService.GetAnnouncementsAsync(query);
        }

        /// <summary>
        /// 获取通知公告详情
        /// </summary>
        [HttpGet("{id}")]
        public async Task<ApiResult<AnnouncementDto>> GetAnnouncement(int id)
        {
            return await _consoleService.GetAnnouncementAsync(id);
        }

        /// <summary>
        /// 创建通知公告
        /// </summary>
        [HttpPost]
        public async Task<ApiResult<AnnouncementDto>> CreateAnnouncement([FromBody] AnnouncementDto dto)
        {
            return await _consoleService.CreateAnnouncementAsync(dto);
        }

        /// <summary>
        /// 更新通知公告
        /// </summary>
        [HttpPut]
        public async Task<ApiResult<AnnouncementDto>> UpdateAnnouncement([FromBody] AnnouncementDto dto)
        {
            return await _consoleService.UpdateAnnouncementAsync(dto);
        }

        /// <summary>
        /// 删除通知公告
        /// </summary>
        [HttpDelete("{id}")]
        public async Task<ApiResult<bool>> DeleteAnnouncement(int id)
        {
            return await _consoleService.DeleteAnnouncementAsync(id);
        }
    }
} 